//
//  UILabel+Extension.swift
//  sina
//
//  Created by shengxinwei on 16/5/24.
//  Copyright © 2016年 shengxinwei. All rights reserved.
//

import UIKit

extension UILabel {
    
    
    //给UILabel 添加一个便利的构造函数
    convenience init(title: String,font: CGFloat,textColor: UIColor,alignment: NSTextAlignment = .Center) {
        
        //调用指定的构造函数 实例化对象
        self.init()
        self.text = title
        self.font = UIFont.systemFontOfSize(font)
        self.textColor = textColor
        textAlignment = alignment
        //设置自动换行
        if alignment == .Left {
            //设置最大布局宽度
            preferredMaxLayoutWidth = ScreenWidth - 2 * cellMargin
        }
        numberOfLines = 0
        //自适应大小
        sizeToFit()
    }
//    convenience init(title: String,font: CGFloat,textColor: UIColor,alignment: NSTextAlignment = .Center) {
//        self.init()
//        let lab = UILabel()
//        lab.text = title
//        lab.font = UIFont.systemFontOfSize(font)
//        lab.textColor = textColor
//        lab.textAlignment = alignment
//        //设置自动换行
//        if alignment == .Left {
//            //设置最大布局宽度
//            preferredMaxLayoutWidth = ScreenWidth - 2 * cellMargin
//        }
//        numberOfLines = 0
//        //自适应大小
//        sizeToFit()
//    }
//    
}
